
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskType;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class TaskTypeServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected TaskTypeService service;

	/**
	 * Instantiates a new TaskTypeServiceTest.
	 *
	 */
	public TaskTypeServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findTaskTypeByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findTaskTypeByPrimaryKey 
		Integer id = 0;
		TaskType response = null;
		response = service.findTaskTypeByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findTaskTypeByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Return a count of all TaskType entity
	* 
	 */
	@Test
	public void countTaskTypes() {
		Integer response = null;
		response = service.countTaskTypes();
		// TODO: JUnit - Add assertions to test outputs of operation: countTaskTypes
	}

	/**
	 * Operation Unit Test
	* Save an existing TaskType entity
	* 
	 */
	@Test
	public void saveTaskType() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskType 
		TaskType tasktype = new cn.edu.scau.cmi.hombio.domain.TaskType();
		service.saveTaskType(tasktype);
	}

	/**
	 * Operation Unit Test
	* Return all TaskType entity
	* 
	 */
	@Test
	public void findAllTaskTypes() {
		// TODO: JUnit - Populate test inputs for operation: findAllTaskTypes 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<TaskType> response = null;
		response = service.findAllTaskTypes(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllTaskTypes
	}

	/**
	 * Operation Unit Test
	* Save an existing Task entity
	* 
	 */
	@Test
	public void saveTaskTypeTasks() {
		// TODO: JUnit - Populate test inputs for operation: saveTaskTypeTasks 
		Integer id_1 = 0;
		Task related_tasks = new cn.edu.scau.cmi.hombio.domain.Task();
		TaskType response = null;
		response = service.saveTaskTypeTasks(id_1, related_tasks);
		// TODO: JUnit - Add assertions to test outputs of operation: saveTaskTypeTasks
	}

	/**
	 * Operation Unit Test
	* Load an existing TaskType entity
	* 
	 */
	@Test
	public void loadTaskTypes() {
		Set<TaskType> response = null;
		response = service.loadTaskTypes();
		// TODO: JUnit - Add assertions to test outputs of operation: loadTaskTypes
	}

	/**
	 * Operation Unit Test
	* Delete an existing Task entity
	* 
	 */
	@Test
	public void deleteTaskTypeTasks() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskTypeTasks 
		Integer tasktype_id = 0;
		Integer related_tasks_id = 0;
		TaskType response = null;
		response = service.deleteTaskTypeTasks(tasktype_id, related_tasks_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteTaskTypeTasks
	}

	/**
	 * Operation Unit Test
	* Delete an existing TaskType entity
	* 
	 */
	@Test
	public void deleteTaskType() {
		// TODO: JUnit - Populate test inputs for operation: deleteTaskType 
		TaskType tasktype_1 = new cn.edu.scau.cmi.hombio.domain.TaskType();
		service.deleteTaskType(tasktype_1);
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
